package dao.impl;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

import dao.JobDao;
import po.emp.Job;

public class JobDaoImpl  implements JobDao{
	private List<Job> jobs;
	public JobDaoImpl() {
		jobs = new LinkedList<>();
	}
	@Override
	public boolean insert(Job t) {
		if (jobs.contains(t)) {
			return false;
		}else {
			return jobs.add(t);
		}
	}

	@Override
	public boolean update(Job t) {
		int indexOf = jobs.indexOf(t);
		if(indexOf == -1) {
			return false;
		}else {
			jobs.set(indexOf, t);
			return true;
		}
	}

	@Override
	public boolean delete(int id) {
		Iterator<Job> it = jobs.iterator();
		while(it.hasNext()) {
			Job next = it.next();
			if( next.getJobId() == id) {
				it.remove();
				return true;
			}
		}
		return false;
	}

	@Override
	public Job selectById(int id) {
		Iterator<Job> it = jobs.iterator();
		while (it.hasNext()) {
			Job next = it.next();
			if(next.getJobId() == id) {
				return next;
			}
		}
		return null;
	}

	@Override
	public List<Job> selectAll() {
		List<Job> j = new LinkedList();
		return j;
	}

}
